package main

import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/elastic/bus"
	"github.com/streadway/amqp"
	"strconv"
)

/*
设置门店的销量、平均分、平均消费价格到ES 交换机=exchange.setShopProperty
*/
func main() {
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("queue.log.setShopProperty"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("queue.setShopProperty"), func(msg amqp.Delivery) {
		// 通过消息队列将分店基本信息添加/更新到ES
		shopId, err := strconv.Atoi(string(msg.Body))
		if err != nil {
			utils.Logerr.Printf("门店id转换成int失败，shopId:%s, err:%s", string(msg.Body), err)
		}
		utils.Logerr.Printf("设置门店的销量、平均分、平均消费价格到ES,接受数据shopId=%d", shopId)
		rpcShop := new(bus.Shop).Init()
		defer rpcShop.Close()
		reply := false
		if err := rpcShop.SetShopProperty(context.Background(), &shopId, &reply); err != nil {
			utils.Logerr.Printf("设置门店的销量、平均分、平均消费价格到Es错误,shopId=%d err：%s",shopId,err.Error())
		}
		utils.Logerr.Printf("设置门店的销量、平均分、平均消费价格到ES处理完成 shopId=%d",shopId)
	})
	if err != nil {
		utils.Logerr.Printf("设置门店的销量、平均分、平均消费价格到ES处理错误 err:%s",err.Error())
	}
}
